'''
Author: kun 56216004@qq.com
Date: 2023-06-27 16:54:49
LastEditors: kun 56216004@qq.com
LastEditTime: 2023-06-27 16:58:09
FilePath: \langchain\30agent.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
# pip install wikipedia
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType


from langchain.llms import OpenAI
import openai
openai.api_base = "https://api.chatanywhere.com.cn/v1"
from config import * 
# openai.api_key = api_key
import os
os.environ["OPENAI_API_KEY"] = api_key # 填入OpenAI Secret Key

llm = OpenAI(model_name="text-davinci-003")

# pip install wikipedia
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
# tools = load_tools(["wikipedia", "llm-math"], llm=llm)  #超时
tools = load_tools([ "llm-math"], llm=llm)
agent = initialize_agent(tools, 
                         llm, 
                         agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, 
                         verbose=True)


agent.run("奥巴马的生日是哪年哪天? 到2023年他多少岁了?")